home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-13 | 6.6 KB | 208 lines | [TEXT/MPS ] |
- (******************************************************************************
- *
- * Apple Macintosh Developer Technical Support
- *
- * Code for the feature determination routines
- *
- * Program: Sample 3.0
- * File: Features.inc1.p - Pascal implementation
- *
- * by: Matt Deatherage
- *
- * Copyright © 1988-1993 Apple Computer, Inc.
- * All rights reserved.
- *
- *******************************************************************************
-
- {$S Initialize}
- (******************************************************************************
- *
- * private: NumToolboxTraps
- *
- * This is straight out of Inside Macintosh (Volume VI, pages 3-8 and 3-9).
- * It checks to see if setting bit 9 of a toolbox trap (InitGraf, in this
- * case) makes a difference in what routine is called. If it doesn't, there
- * are $200 toolbox traps, but if it does, there are $400 traps. Used by
- * TrapAvailalble in this unit.
- *
- ******************************************************************************)
-
- FUNCTION NumToolboxTraps: INTEGER;
-
- CONST
- _InitGraf = $A86E; { Trap number for the InitGraf trap }
-
- BEGIN
- IF NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E,
- ToolTrap) THEN
- NumToolboxTraps := $200
- ELSE
- NumToolboxTraps := $400;
- END; {NumToolboxTraps}
-
- {$S Initialize}
- (******************************************************************************
- *
- * private: GetTrapType
- *
- * This is straight out of Inside Macintosh (Volume VI, pages 3-8 and 3-9).
- * It checks bit eight of a trap instruction to see if it's a Toolbox trap
- * or an OS trap.
- *
- ******************************************************************************)
-
- FUNCTION GetTrapType(theTrap: INTEGER): TrapType;
-
- CONST
- TrapMask = $0800; { Only bit eight is significant }
-
- BEGIN
- IF BAND(theTrap, TrapMask) > 0 THEN
- GetTrapType := ToolTrap
- ELSE
- GetTrapType := OSTrap;
- END; {GetTrapType}
-
- {$S Initialize}
- (******************************************************************************
- *
- * private: TrapAvailable
- *
- * This is straight out of Inside Macintosh (Volume VI, pages 3-8 and 3-9).
- * It checks to see if a given trap is implemented. The address in the
- * trap dispatch tables is compared against the address of the standard
- * Unimplemented trap. If they're the same, the trap is unimplemented. By
- * definition, the trap is also not implemented if it's a Toolbox trap but
- * beyond the end of the range of Toolbox traps. The BOOLEAN result returns
- * whether or not the trap is implemented.
- *
- ******************************************************************************)
-
- FUNCTION TrapAvailable(theTrap: INTEGER): BOOLEAN;
-
- CONST
- _Unimplemented = $A89F;
-
- VAR
- tType: TrapType; { the type of theTrap }
-
- BEGIN
- tType := GetTrapType(theTrap);
- IF tType = ToolTrap THEN
- BEGIN
- theTrap := BAND(theTrap, $07FF);
- IF theTrap >= NumToolboxTraps THEN
- theTrap := _Unimplemented;
- END;
- TrapAvailable := NGetTrapAddress(theTrap, tType) <>
- NGetTrapAddress(_Unimplemented, ToolTrap);
- END; {TrapAvailable}
-
- {$S Initialize}
- (******************************************************************************
- *
- * Public: DetermineFeatures
- *
- * DetermineFeatures checks for all the features our application needs. It
- * sets several global variables based on the results and returns TRUE if
- * the required features are implemented. As written here, the only required
- * feature is having Gestalt implemented, which lets us check for all the
- * rest of the features we want to know about.
- *
- * Note that in many cases, the check for the _Gestalt trap is unnecessary.
- * MPW 3.2 and later link in glue code that always makes Gestalt available.
- * If you know your development environment does this, or if you are requiring
- * System 6.0.4 or later (highly recommended), you can remove the check for
- * Gestalt (as well as NumToolboxTraps, GetTrapType and TrapAvailable unless
- * you call them in another place, like we do when checking for DeviceLoop).
- * If you remove the calls, remember to set gHasGestalt to TRUE.
- *
- ******************************************************************************)
-
- FUNCTION DetermineFeatures: BOOLEAN;
-
- CONST
- _Gestalt = $A1AD; { trap number for Gestalt }
- _DeviceLoop = $ABCA; { trap number for DeviceLoop }
-
- VAR
- featureErr: OSErr; { error variable to use with Gestalt }
- tempResult: LONGINT; { temporary variable for Gestalt results }
- tempBit: INTEGER; { temporary variable for bit manipulation:
- Pascal doesn't let you pass constants to
- library routines like BTST }
-
- BEGIN
-
- gHasGestalt := TrapAvailable(_Gestalt);
- IF gHasGestalt THEN
- BEGIN
-
- { Check for Balloon Help by testing for the Help Manager }
-
- tempBit := gestaltHelpMgrPresent;
- featureErr := Gestalt(gestaltHelpMgrAttr, tempResult);
- IF featureErr = noErr THEN
- gHasHelpMgr := BTst(tempResult, tempBit)
- ELSE
- gHasHelpMgr := FALSE;
-
- { Check for color QuickDraw and 32-bit QuickDraw. This is to work
- around a System 7 problem that occasionally makes Gestalt report
- there's color QuickDraw when there isn't. This method always
- works. }
-
- featureErr := Gestalt(gestaltQuickdrawVersion, tempResult);
- gHasColorQD := FALSE;
- gHas32BitQD := FALSE;
- IF featureErr = noErr THEN
- BEGIN
- tempResult := BSR(tempResult, 8); { Shift the major version
- into the low byte }
- CASE tempResult OF
- 1:
- gHasColorQD := TRUE;
- 2:
- BEGIN
- gHasColorQD := TRUE;
- gHas32BitQD := TRUE;
- END;
- END;
- END;
-
- { Check for FindFolder. Like with Gestalt, you can avoid this test
- if you know your development environment provides glue for this
- call like MPW 3.2 and later do. }
-
- gHasFindFolder := FALSE;
- featureErr := Gestalt(gestaltFindFolderAttr, tempResult);
- IF featureErr = noErr THEN
- gHasFindFolder := BTst(tempResult, gestaltFindFolderPresent);
-
- { Check for the DeviceLoop trap. }
-
- gHasDeviceLoop := TrapAvailable(_DeviceLoop);
-
- { Check for the Apple Events Manager. You'll crash if you call it
- when it's not implemented, such as under System 6. }
-
- gHasAppleEvents := FALSE;
- tempBit := gestaltAppleEventsPresent;
- featureErr := Gestalt(gestaltAppleEventsAttr, tempResult);
- IF featureErr = noErr THEN
- gHasAppleEvents := BTst(tempResult, tempBit);
-
- { Keep a copy of our application's resource file around. Since we
- call DetermineFeatures before doing any resource file
- manipulations, we're still the current resource file. }
-
- gAppsResourceFile := CurResFile;
-
- { Add more features here if you need them. }
-
- END; { if gHasGestalt then }
-
- DetermineFeatures := gHasGestalt; { We have no features if we have no Gestalt
- here. }
- END; {DetermineFeatures}
-